package com.clock.web.controller.shop;

import com.clock.common.annotation.Log;
import com.clock.common.core.controller.BaseController;
import com.clock.common.core.domain.AjaxResult;
import com.clock.common.core.page.TableDataInfo;
import com.clock.common.enums.BusinessType;
import com.clock.common.utils.poi.ExcelUtil;

import com.clock.shop.domain.ShopActivity;
import com.clock.shop.domain.vo.ActivityVo;
import com.clock.shop.service.IShopActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 活动信息Controller
 * 
 * @author ruoyi
 * @date 2024-10-11
 */
@RestController
@RequestMapping("/shop/activity")
public class ShopActivityController extends BaseController
{
    @Autowired
    private IShopActivityService shopActivityService;

    /**
     * 查询活动信息列表
     */
    // @PreAuthorize("@ss.hasPermi('shop:activity:list')")
    @GetMapping("/list")
    public TableDataInfo list(ActivityVo activityVo)
    {
        startPage();
        List<ActivityVo> list = shopActivityService.selectShopActivityList(activityVo);
        return getDataTable(list);
    }

    /**
     * 导出活动信息列表
     */
    @PreAuthorize("@ss.hasPermi('shop:activity:export')")
    @Log(title = "活动信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ActivityVo activityVo)
    {
        List<ActivityVo> list = shopActivityService.selectShopActivityList(activityVo);
        ExcelUtil<ActivityVo> util = new ExcelUtil<ActivityVo>(ActivityVo.class);
        util.exportExcel(response, list, "活动信息数据");
    }

    /**
     * 获取活动信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:activity:query')")
    @GetMapping(value = "/{activityId}")
    public AjaxResult getInfo(@PathVariable("activityId") Long activityId)
    {
        return success(shopActivityService.selectShopActivityByActivityId(activityId));
    }

    /**
     * 新增活动信息
     */
    @PreAuthorize("@ss.hasPermi('shop:activity:add')")
    @Log(title = "活动信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ActivityVo activityVo)
    {
        return toAjax(shopActivityService.insertShopActivity(activityVo));
    }

    /**
     * 修改活动信息
     */
    @PreAuthorize("@ss.hasPermi('shop:activity:edit')")
    @Log(title = "活动信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ShopActivity shopActivity)
    {
        return toAjax(shopActivityService.updateShopActivity(shopActivity));
    }

    /**
     * 删除活动信息
     */
    @PreAuthorize("@ss.hasPermi('shop:activity:remove')")
    @Log(title = "活动信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{activityIds}")
    public AjaxResult remove(@PathVariable Long[] activityIds)
    {
        return toAjax(shopActivityService.deleteShopActivityByActivityIds(activityIds));
    }
}
